package site.wanjiahao.message;


import lombok.Data;
import site.wanjiahao.message.request.*;
import site.wanjiahao.message.response.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 公共抽象父类，消息类型
 */
@Data
public abstract class Message {

    private static final Map<Integer, Class<? extends Message>> map = new HashMap<>();

    protected static final int RPC_REQUEST_ID = 1;
    protected static final int RPC_RESPONSE_ID = 2;
    protected static final int PING_MESSAGE_ID = 3;
    protected static final int PONG_MESSAGE_ID = 4;

    private Long sequenceId;

    static {
        map.put(RPC_REQUEST_ID, RpcRequestMessage.class);
        map.put(RPC_RESPONSE_ID, RpcResponseMessage.class);
        map.put(PING_MESSAGE_ID, PingMessage.class);
        map.put(PONG_MESSAGE_ID, PongMessage.class);
    }

    public Message() {
        this.sequenceId = System.currentTimeMillis();
    }

    public static Class<? extends Message> getClazz(int key) {
        return map.get(key);
    }

    public abstract int getMessageType();

}
